import Tool,os

cookies=""
session=""

#read cookie
ck=Tool.file_readFile("cookie.txt")
print(ck)
ret = Tool.web_get("https://url.cccyun.cc/user/forward-list.php",ck)
if(ret.find("login.php?logout")!=-1):
    print( "缓存有效" )
    session="1"
    cookies=ck
else:
    print("缓存无效")
    ret = Tool.web_post( "https://url.cccyun.cc/user/login.php" , "email=xpcxpc.ok%40163.com&pass=547896321" , "" )
    if ret.find( "登陆成功" ) != -1:
        print( "登陆成功" )
    else:
        print( "登陆失败" )
    # print(ret)

    session = Tool.text_getMiddle( ret , "PHPSESSID#单引号#冒号 #单引号" , "#单引号" )
    userid = Tool.text_getMiddle( ret , "user_id#单引号#冒号 #单引号" , "#单引号" )
    user_key = Tool.text_getMiddle( ret , "user_key#单引号#冒号 #单引号" , "#单引号" )
    print( session , userid , user_key )
    cookies="PHPSESSID=" + session[ 0 ] + "; user_id=" + userid[ 0 ] + "; user_key=" + user_key[ 0 ]

if len(session[ 0 ])!="":
    # save cookie
    Tool.file_writeToTxt( "cookie.txt" ,cookies )

    ret = Tool.web_post("https://url.cccyun.cc/user/forward-edit.php?id=19176","mode=0&url=http%3A%2F%2Fnote.rrblogs.com%2F&title=&keywords=&description=&park=default.html",cookies)
    print(ret)